/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * usuarios_incluir.java
 *
 * Created on 28/05/2011, 12:39:19
 */
package Visualização;

import javax.swing.JOptionPane;

/**
 *
 * @author Fabio
 */
public class usuarios_incluir extends javax.swing.JFrame {

    /** Creates new form usuarios_incluir */
    public usuarios_incluir() {
        initComponents();
        setLocationRelativeTo( null ); 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tituloLabel = new javax.swing.JLabel();
        nomeLabel = new javax.swing.JLabel();
        matriculaLabel = new javax.swing.JLabel();
        emailLabel = new javax.swing.JLabel();
        cargoLabel = new javax.swing.JLabel();
        loginLabel = new javax.swing.JLabel();
        senhaLabel = new javax.swing.JLabel();
        confirmarSenhaLabel = new javax.swing.JLabel();
        nomeInput = new javax.swing.JTextField();
        matriculaInput = new javax.swing.JTextField();
        emailInput = new javax.swing.JTextField();
        loginInput = new javax.swing.JTextField();
        gravarButton = new javax.swing.JButton();
        cancelarButton = new javax.swing.JButton();
        cargoSelect = new javax.swing.JComboBox();
        senhaInput = new javax.swing.JPasswordField();
        confirmarSenhaInput = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setLocationByPlatform(true);
        setResizable(false);

        tituloLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        tituloLabel.setText("Incluir Usuário");

        nomeLabel.setText("Nome:");

        matriculaLabel.setText("Matrícula:");

        emailLabel.setText("E-mail:");

        cargoLabel.setText("Cargo:");

        loginLabel.setText("Login:");

        senhaLabel.setText("Senha:");

        confirmarSenhaLabel.setText("Confirmar Senha:");

        gravarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Salvar.png"))); // NOI18N
        gravarButton.setText("Gravar");
        gravarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gravarButtonActionPerformed(evt);
            }
        });

        cancelarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Cancelar.png"))); // NOI18N
        cancelarButton.setText("Cancelar");
        cancelarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarButtonActionPerformed(evt);
            }
        });

        cargoSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "                  ", "Administrador", "Supervisor", "Usuário" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tituloLabel)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nomeLabel)
                            .addComponent(matriculaLabel)
                            .addComponent(emailLabel)
                            .addComponent(cargoLabel)
                            .addComponent(loginLabel)
                            .addComponent(senhaLabel)
                            .addComponent(confirmarSenhaLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(confirmarSenhaInput)
                            .addComponent(senhaInput)
                            .addComponent(cargoSelect, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(loginInput)
                            .addComponent(emailInput)
                            .addComponent(matriculaInput, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(nomeInput, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(gravarButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelarButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tituloLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomeLabel)
                    .addComponent(nomeInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(matriculaLabel)
                    .addComponent(matriculaInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailLabel)
                    .addComponent(emailInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cargoLabel)
                    .addComponent(cargoSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(loginLabel)
                    .addComponent(loginInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(senhaLabel)
                    .addComponent(senhaInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(confirmarSenhaLabel)
                    .addComponent(confirmarSenhaInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gravarButton)
                    .addComponent(cancelarButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void gravarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gravarButtonActionPerformed
        BO.usuarioBO uBO;
        Negocio.usuario u;
        
        uBO = new BO.usuarioBO();
        uBO.setMatriculaBO(Integer.parseInt(this.matriculaInput.getText()));
        uBO.setLoginBO(this.loginInput.getText());
        uBO.setSenhaBO(this.senhaInput.getText());
        uBO.setSenhaConfirmaBO(this.confirmarSenhaInput.getText());
        uBO.setNomeBO(this.nomeInput.getText());
        uBO.setEmailBO(this.emailInput.getText());
        uBO.setCargoBO(this.cargoSelect.getSelectedIndex());
        
        u = new Negocio.usuario();
        u.SalvarUsuario(uBO, this);
        
        JOptionPane.showMessageDialog(null, "Usuário criado com sucesso!");
        limpar();
    }//GEN-LAST:event_gravarButtonActionPerformed

    private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelarButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new usuarios_incluir().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarButton;
    private javax.swing.JLabel cargoLabel;
    private javax.swing.JComboBox cargoSelect;
    private javax.swing.JPasswordField confirmarSenhaInput;
    private javax.swing.JLabel confirmarSenhaLabel;
    private javax.swing.JTextField emailInput;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JButton gravarButton;
    private javax.swing.JTextField loginInput;
    private javax.swing.JLabel loginLabel;
    private javax.swing.JTextField matriculaInput;
    private javax.swing.JLabel matriculaLabel;
    private javax.swing.JTextField nomeInput;
    private javax.swing.JLabel nomeLabel;
    private javax.swing.JPasswordField senhaInput;
    private javax.swing.JLabel senhaLabel;
    private javax.swing.JLabel tituloLabel;
    // End of variables declaration//GEN-END:variables

    private void limpar() {
        nomeInput.setText("");
        matriculaInput.setText("");
        emailInput.setText("");
        cargoSelect.setSelectedIndex(0);
        loginInput.setText("");
        senhaInput.setText("");
        confirmarSenhaInput.setText("");
    }
}
